class Typer {
    #message
    #write
    #index = 0
    
    constructor(msg, write) {
        this.#message = msg + '☺'
        this.#write = write
        this.interval = setInterval(this.#type, 100)
    }

    #type = () => {
        const str = this.#message[this.#index];
        if (!str) {
            clearInterval(this.interval)
            return
        }
        this.#write(str)
        this.#index++
    }
}

module.exports = Typer
